GetEventByIdQueryHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 32
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 28 2
1
import { QueryHandler } from '@nestjs/cqrs';
2
import { Inject } from '@nestjs/common';
3
import { GetEventByIdQuery } from './GetEventByIdQuery';
4
import { EventDetailView } from '../View/EventDetailView';
5
import { IEventRepository } from 'src/Domain/Calendar/Repository/IEventRepository';
6
import { EventNotFoundException } from 'src/Domain/Calendar/Exception/EventNotFoundException';
7
import { SchoolSummaryView } from 'src/Application/School/View/SchoolSummaryView';
8
import { UserSummaryView } from 'src/Application/User/View/UserSummaryView';
9
10
@QueryHandler(GetEventByIdQuery)
11
export class GetEventByIdQueryHandler {
12
  constructor(
13
    @Inject('IEventRepository')
14
    private readonly eventRepository: IEventRepository
15
  ) {}
16
17
  public async execute({ id }: GetEventByIdQuery): Promise<EventDetailView> {
18
    const event = await this.eventRepository.findOneById(id);
19
    if (!event) {
20
      throw new EventNotFoundException();
21
    }
22
23
    const school = event.getSchool();
24
    const user = event.getPhotographer();
25
26
    return new EventDetailView(
27
      event.getId(),
28
      new SchoolSummaryView(
29
        school.getId(),
30
        school.getName(),
31
        school.getReference(),
32
        school.getAddress(),
33
        school.getCity(),
34
        school.getZipCode(),
35
      ),
36
      new UserSummaryView(
37
        user.getId(),
38
        user.getFirstName(),
39
        user.getLastName(),
40
        user.getEmail(),
41
      ),
42
      event.getDate(),
43
      event.getSummary()
44
    );
45
  }
46
}
47